import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

import menu from './modules/menu'
import role from './modules/role'
import manger from './modules/manger'
import cate from './modules/cate'
import specs from './modules/specs'
import goods from './modules/goods'
import member from './modules/member'
import banner from './modules/banner'
import seck from './modules/seck'

const state = {
  userInfo: sessionStorage.getItem('user') ? JSON.parse(sessionStorage.getItem('user')) : null
}

const getters = {
  getUser(state){
    return state.userInfo
  }
}

const mutations ={
  REQ_GETUSER(state, payload){
    if(payload){
      state.userInfo = payload
      sessionStorage.setItem('user',JSON.stringify(payload))
    }else{
      sessionStorage.removeItem('user')
    }
    
  }
}

const actions = {
  getUserInfoAction({commit},payload){
    commit('REQ_GETUSER',payload)
  }
}

export default new Vuex.Store({
  state,
  mutations,
  getters,
  actions,
  modules:{
    menu,
    role,
    manger,
    cate,
    specs,
    goods,
    member,
    banner,
    seck
  }
})